document.getElementById('registrationForm').addEventListener('submit', function(event) {
    event.preventDefault(); // 阻止表单的默认提交行为  

    // 收集表单数据  
    const formData = {
        username: document.getElementById('username').value,
        password: document.getElementById('password').value,
        email: document.getElementById('email').value,
        userage: parseInt(document.getElementById('age').value, 10), // 转换为整数
        usersex: document.getElementById('sex').value,
        useraddress: document.getElementById('address').value
    };

    // 使用axios发送POST请求  
    axios.post('/register', formData)
        .then(response => {
            // 处理响应  
            if (response.data.success) {
                document.getElementById('response-message').innerText = '注册成功!';
                // 可能还需要清除表单或进行其他操作  
            } else {
                document.getElementById('response-message').innerText = '注册失败: ' + response.data.message;
            }
        })
        .catch(error => {
            // 处理请求错误  
            document.getElementById('response-message').innerText = '注册过程中发生错误: ' + error.message;
        });
});